package com.selfdriving.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.selfdriving.BaseApplication;
import com.selfdriving.BaseObjectListAdapter;
import com.selfdriving.R;
import com.selfdriving.bean.Entity;
import com.selfdriving.bean.Strategy;
import com.selfdriving.view.CircularImage;

public class WMyStrategyAdapter extends BaseObjectListAdapter
{
	BaseApplication application;
	Context context;
	List<? extends Entity> datas;

	public WMyStrategyAdapter(BaseApplication application, Context context,
			List<? extends Entity> datas)
	{
		super(application, context, datas);
		this.application = application;
		this.context = context;
		this.datas = datas;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.w_item_strategy, null);
			holder = new ViewHolder();
			holder.img = (ImageView) convertView
					.findViewById(R.id.strategy_img);
			holder.title = (TextView) convertView
					.findViewById(R.id.strategy_title);
			holder.time = (TextView) convertView
					.findViewById(R.id.strategy_time);
			holder.location = (TextView) convertView
					.findViewById(R.id.strategy_location);
			holder.name = (TextView) convertView
					.findViewById(R.id.strategy_userName);
			holder.avatar = (CircularImage) convertView
					.findViewById(R.id.strategy_avatar);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		if (datas != null)
		{
			holder.avatar.setVisibility(View.VISIBLE);
			holder.name.setVisibility(View.VISIBLE);
			Strategy strategy = (Strategy) datas.get(position);
			application.imageLoader.displayImage(strategy.getImg(), holder.img,
					application.options);
			application.imageLoader.displayImage(strategy.getAvatar(),
					holder.avatar, application.options);
			holder.title.setText(strategy.getTitle());
			holder.time.setText(strategy.getTime());
			holder.location.setText(strategy.getLoaction());
			holder.name.setText(strategy.getName());
		}
		return convertView;
	}

	class ViewHolder
	{
		ImageView img;
		TextView title;
		TextView time;
		TextView location;
		CircularImage avatar;
		TextView name;
	}
}
